package tankgame03_manybullet;

import java.util.Vector;

public class Tank {
    private int x;
    private int y;
    private int dirct; //0123 上左下右
    private int type;//0自己 1敌人
    private int speed=2;
    private  boolean islive = true;

    public boolean isIslive() {
        return islive;
    }

    public void setIslive(boolean islive) {
        this.islive = islive;
    }

    private Vector<MyBullet> mybullets =new Vector<>();
    private Vector<EnBullet> enBullets =new Vector<>();

    public Vector<MyBullet> getMybullets() {
        return mybullets;
    }

    public Vector<EnBullet> getEnBullets() {
        return enBullets;
    }

    //发射子弹
    public void shoot() {
        if (this instanceof Hero) {
            if (mybullets.size() > 2) {
                return;
            }
            switch (dirct) {
                case 0:
                    MyBullet bullet0 = new MyBullet(x + 20, y, 0);
                    mybullets.add(bullet0);
                    break;
                case 1:
                    MyBullet bullet1 = new MyBullet(x + 60, y + 20, 1);
                    mybullets.add(bullet1);
                    break;
                case 2:
                    MyBullet bullet2 = new MyBullet(x + 20, y + 60, 2);
                    mybullets.add(bullet2);
                    break;
                case 3:
                    MyBullet bullet3 = new MyBullet(x, y + 20, 3);
                    mybullets.add(bullet3);
                    break;
            }
            for (MyBullet bul : mybullets
            ) {
                new Thread(bul).start();
            }

        } else if ( this instanceof EnemyTank) {
            if (enBullets.size() > 2) {
                return;
            }
            switch (dirct) {
                case 0:
                    EnBullet bullet0 = new EnBullet(x + 20, y, 0);
                    enBullets.add(bullet0);
                    break;
                case 1:
                    EnBullet bullet1 = new EnBullet(x + 60, y + 20, 1);
                    enBullets.add(bullet1);
                    break;
                case 2:
                    EnBullet bullet2 = new EnBullet(x + 20, y + 60, 2);
                    enBullets.add(bullet2);
                    break;
                case 3:
                    EnBullet bullet3 = new EnBullet(x, y + 20, 3);
                    enBullets.add(bullet3);
                    break;
            }
            for (EnBullet bul : enBullets
            ) {
                new Thread(bul).start();
            }
        }

    }



    public  void  moveUp(){
        y-=speed;
    }
    public  void  moveRight(){
        x+=speed;
    }
    public  void  moveDown(){
        y+=speed;
    }
    public  void  moveLeft(){
        x-=speed;
    }

    public int getSpeed() {
        return speed;
    }

    public void setSpeed(int speed) {
        this.speed = speed;
    }

    public int getDirct() {
        return dirct;
    }

    public void setDirct(int dirct) {
        this.dirct = dirct;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public Tank(int x, int y) {
        this.x = x;
        this.y = y;

    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }
}
